package com.cjj.service.impl;

import com.cjj.service.FollowDiaryService;
import com.cjj.vo.FollowDetailsVo;
import com.cjj.vo.FollowDiaryVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.mapper.TInterposeFollowupVisitMapper;
import com.guigu.mapper.TMemberMapper;
import com.guigu.mapper.TOrderMapper;
import com.guigu.pojo.TFollowDetails;
import com.guigu.pojo.TInterposeFollowupVisit;
import com.guigu.pojo.TMember;
import com.guigu.pojo.TOrder;
import com.guigu.viwe.PageVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class FollowDiaryServiceImpl implements FollowDiaryService {

    @Resource
    private TInterposeFollowupVisitMapper tInterposeFollowupVisitMapper;

    @Resource
    private TMemberMapper tMemberMapper;


    //分页查询
    @Override
    public PageInfo<FollowDiaryVo> queryFollowDiary(PageVo<FollowDiaryVo> pageVo) {
        PageHelper.startPage(pageVo.getCurrentPage(), pageVo.getPageSize());
        PageInfo<FollowDiaryVo> ClassifyPageInfo = new PageInfo<>(this.tInterposeFollowupVisitMapper.queryFollowDiary(pageVo.getCondition()));
        return ClassifyPageInfo;
    }

    //查找被干预人
    @Override
    public List<TMember> queryInterferedPerson() {

        return this.tMemberMapper.queryInterferedPerson();
    }

    @Override
    public int addFollow(FollowDetailsVo followDetailsVo) {
        this.tInterposeFollowupVisitMapper.insertFollow(followDetailsVo);
        if (followDetailsVo.getTFollowDetails().size() > 0) {
            for (int i=0; i<followDetailsVo.getTFollowDetails().size();i++){
                TFollowDetails tFollowDetails = followDetailsVo.getTFollowDetails().get(i);
                tFollowDetails.setFollowId(followDetailsVo.getId());
                this.tInterposeFollowupVisitMapper.insertFollowFile(tFollowDetails);
            }
        }
        return 1;
    }

    @Override
    public int updateFollow(TInterposeFollowupVisit tInterposeFollowupVisit) {
        return this.tInterposeFollowupVisitMapper.updateByPrimaryKeySelective(tInterposeFollowupVisit);
    }
//修改状态
    @Override
    public int deleteRow(String fileNumber) {
        TMember tMember = this.tMemberMapper.queryTMember(fileNumber);
        return this.tInterposeFollowupVisitMapper.updateOrder(tMember.getId());
    }


}
